Micron Document
rns.moscow 🟥 [git]


Commit 306cb6fd3a8ef61ba0cdd011099e5bc74438850a


Parents : 49d5efc
Author : Nickie Deuxyeux <nikolay@dvoeglazov.ru>
Date : 2026-07-16T19:37:00+03:00

Fix NTP RTC sync status parsing and add per-reason error messages

rtc_sync_ntp() now returns a reason code (0 = success) instead of a
bare success flag, so a previous sync could report failure inverted
(0x00 misread as success). Parse the new status byte correctly and
surface the specific failure reason (no RTC, no network, NTP timeout,
RTC write failure) instead of a generic message, mirroring the
on-device Settings menu's new Sync NTP result popup.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

Changes

2 files changed, 28 insertions(+), 6 deletions(-)


Diff

diff --git a/htdocs/index.html b/htdocs/index.html
index fa31046..deb5ada 100644
--- a/htdocs/index.html
+++ b/htdocs/index.html
@@ -651,6 +651,10 @@ class RNode {
CMD_ETH_IP = 0x88; CMD_ETH_NM = 0x89; CMD_ETH_SPEED = 0x8A;
CMD_WIFI_GW = 0x8C; CMD_WIFI_DNS = 0x8D; CMD_ETH_GW = 0x8E; CMD_ETH_DNS = 0x8F;
CMD_NTP_SYNC = 0x8B;
+ // rtc_sync_ntp()'s reason code (RTC.h) - 0 is success, matching C
+ // convention; anything else is a specific failure reason.
+ NTP_SYNC_OK = 0; NTP_SYNC_ERR_NO_RTC = 1; NTP_SYNC_ERR_NO_NET = 2;
+ NTP_SYNC_ERR_TIMEOUT = 3; NTP_SYNC_ERR_RTC_WRITE = 4;
CMD_BT_CTRL = 0x46; CMD_BT_PIN = 0x62;
ROM_UNLOCK_BYTE = 0xF8; HASH_TYPE_FIRMWARE = 0x02;
@@ -870,11 +874,12 @@ class RNode {
// Blocks on-device for up to NTP_SYNC_TIMEOUT_MS (RTC.h, 5s) while it
// resolves and queries pool.ntp.org, so give it a generous timeout.
// Replies under its own command byte (kiss_indicate_ntp_sync(), firmware
- // Utilities.h) with a leading success byte followed by the 4-byte epoch -
- // not just a bare epoch like CMD_TIME's response.
+ // Utilities.h) with a leading status byte (NTP_SYNC_OK/NTP_SYNC_ERR_*
+ // above - 0 means success) followed by the 4-byte epoch, not just a
+ // bare epoch like CMD_TIME's response.
async syncNtp() {
const r = await this.sendCmd(this.CMD_NTP_SYNC, [0x01], 10000);
- return { success: r[0] === 0x01, epoch: (r[1]<<24 | r[2]<<16 | r[3]<<8 | r[4]) >>> 0 };
+ return { status: r[0], epoch: (r[1]<<24 | r[2]<<16 | r[3]<<8 | r[4]) >>> 0 };
}
async enableBluetooth() { await this.sendKissOnly([this.CMD_BT_CTRL, 0x01]); }
@@ -3390,13 +3395,20 @@ Vue.createApp({
async syncRtcFromNtp() {
await this.withRNode(this.t('step.syncing_rtc_ntp'), async (rnode) => {
this.addLog('cmd', '$ ', 'syncing RTC from NTP...');
- const { success, epoch } = await rnode.syncNtp();
+ const { status, epoch } = await rnode.syncNtp();
this.rtcTime = epoch;
- if (success) {
+ if (status === rnode.NTP_SYNC_OK) {
this.addLog('ok', ' ✓ ', `RTC synced: ${this.rtcTimeDisplay}`);
this.statusType = 'success'; this.statusMsg = this.t('status.rtc_synced');
} else {
- this.addLog('err', ' ✗ ', 'NTP sync failed — check network connection.');
+ const reasonKeys = {
+ [rnode.NTP_SYNC_ERR_NO_RTC]: 'rtc.ntp_err.no_rtc',
+ [rnode.NTP_SYNC_ERR_NO_NET]: 'rtc.ntp_err.no_net',
+ [rnode.NTP_SYNC_ERR_TIMEOUT]: 'rtc.ntp_err.timeout',
+ [rnode.NTP_SYNC_ERR_RTC_WRITE]: 'rtc.ntp_err.rtc_write',
+ };
+ const reason = this.t(reasonKeys[status] || 'rtc.ntp_err.unknown');
+ this.addLog('err', ' ✗ ', `NTP sync failed — ${reason}`);
this.statusType = 'error'; this.statusMsg = this.t('status.rtc_sync_failed');
}
});

diff --git a/htdocs/js/i18n.js b/htdocs/js/i18n.js
index 069e79c..95f9081 100644
--- a/htdocs/js/i18n.js
+++ b/htdocs/js/i18n.js
@@ -118,6 +118,11 @@ window.i18n = {
'misc.rtc.unavailable': '— (недоступно)',
'btn.rtc_sync_browser': 'Синхронизировать с браузером',
'btn.rtc_sync_ntp': 'Синхронизировать по NTP',
+ 'rtc.ntp_err.no_rtc': 'RTC-микросхема не обнаружена.',
+ 'rtc.ntp_err.no_net': 'нет подключения к сети.',
+ 'rtc.ntp_err.timeout': 'истекло время ожидания NTP-сервера.',
+ 'rtc.ntp_err.rtc_write': 'не удалось записать время в RTC.',
+ 'rtc.ntp_err.unknown': 'неизвестная ошибка.',
'footer.firmware': 'Архив прошивок',
'footer.source': 'Исходный код',
@@ -349,6 +354,11 @@ window.i18n = {
'misc.rtc.unavailable': '— (unavailable)',
'btn.rtc_sync_browser': 'Sync from browser',
'btn.rtc_sync_ntp': 'Sync from NTP',
+ 'rtc.ntp_err.no_rtc': 'no RTC chip detected.',
+ 'rtc.ntp_err.no_net': 'no network connection.',
+ 'rtc.ntp_err.timeout': 'NTP server request timed out.',
+ 'rtc.ntp_err.rtc_write': 'failed to write the RTC.',
+ 'rtc.ntp_err.unknown': 'unknown error.',
'footer.firmware': 'Firmware archive',
'footer.source': 'Firmware source-code',

Served by rngit 1.4.2 - Generated in 0.06s